package com.windowes.weichang.startup;

import com.windowes.weichang.component.redis.RedisService;
import com.windowes.weichang.service.DistrictService;
import com.windowes.weichang.subscribe.RedisSubscribe;
import com.windowes.weichang.subscribe.TaskHandleService;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/***
 *
 * @author: yangqing
 * @email: qing.yang@bangdao-tech.com
 * @createTime: 2018/7/14 下午6:31
 * @description: 启动
 *
 **/
@Component
public class Startup implements InitializingBean {

    @Autowired
    DistrictService districtService;

    @Autowired
    RedisService redisService;

    @Autowired
    TaskHandleService taskHandleService;


    @Override
    public void afterPropertiesSet() throws Exception {
        districtService.init();
        registerRedisSubscribe();
    }

    private void registerRedisSubscribe() {
        new Thread(()->{
            redisService.subscribe(new RedisSubscribe(taskHandleService), "__keyevent@0__:expired");
        }).start();
    }

}
